package com.sskj.kafka.v1;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author MaSiyi
 * @version 1.0.0 2021/12/10
 * @since JDK 1.8.0
 */
@RestController
public class KafkaProducer {

    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    /** 发送消息
     * @Param:
     * @return:
     * @Author: MaSiyi
     * @Date: 2021/12/10
     */
    @PostMapping("/kafka/normal/{topic}")
    public void sendMessage1(@PathVariable("topic") String topic, @RequestBody Map<String, Object> normalMessage) {
        kafkaTemplate.send(topic, JSON.toJSONString(normalMessage));
    }

}

